﻿function(get_boost)


    find_package(Boost COMPONENTS system REQUIRED)

    if (Boost_FOUND)
        message("Boost : ${Boost_INCLUDE_DIRS}")
        message("Boost : ${Boost_LIBRARY_DIRS}")
        message("Boost : ${Boost_LIBRARIES}")

        message("Boost : ${BOOST_INCLUDE_DIRS}")
        message("Boost : ${BOOST_LIBRARY_DIRS}")
        message("Boost : ${BOOST_LIBRARIES}")


        include_directories(${Boost_INCLUDE_DIRS})
        link_directories(${Boost_LIBRARY_DIRS})
        link_libraries(${Boost_LIBRARIES})
        if (WIN32)
            link_libraries(boost_filesystem-vc140-mt-gd.lib)
        endif ()
    endif ()


endfunction()

function(get_glog)

    find_package(glog CONFIG REQUIRED)
    if (glog_FOUND)
        message("glog : ${glog_INCLUDE_DIRS}")
        message("glog : ${glog_LIBRARY_DIRS}")

        message("glog : ${GLOG_INCLUDE_DIRS}")
        message("glog : ${GLOG_LIBRARY_DIRS}")

        include_directories(${glog_INCLUDE_DIRS})
        link_directories(${glog_LIBRARY_DIRS})
        link_libraries(glog::glog)
    endif ()

endfunction()

function(get_gtest)

    find_package(GTest MODULE REQUIRED)#查找GTest

    if (GTest_FOUND)
        message("gtest_include_dir=${GTEST_INCLUDE_DIR}")
        message("gtest_library=${GTEST_LIBRARY}")
        include_directories(${GTEST_INCLUDE_DIRS})
        link_directories(${GTEST_LIBRARY_DIRS})
        link_libraries(GTest::gmock GTest::gtest GTest::gmock_main GTest::gtest_main)
    endif ()

endfunction()

function(get_benchmark)
    find_package(benchmark CONFIG REQUIRED)
    link_libraries(benchmark::benchmark benchmark::benchmark_main)
endfunction()

function(get_all_test)
    get_gtest()
    get_benchmark()
endfunction()

function(get_fmt)

    find_package(fmt CONFIG REQUIRED)

    if (fmt_FOUND)
        message("fmt_include_dir=${fmt_INCLUDE_DIRS}")
        message("fmt_library=${fmt_LIBRARYS}")

        message("fmt_include_dir=${FMT_INCLUDE_DIRS}")
        message("fmt_library=${FMT_LIBRARYS}")


        include_directories(${fmt_INCLUDE_DIRS})
        link_directories(${fmt_LIBRARY_DIRS})

        if (use_fmt_header_only)
            # Or use the header-only version
            link_libraries(fmt::fmt-header-only)
        else ()
            # use libary
            link_libraries(fmt::fmt)
        endif ()
    endif ()

endfunction()

function(get_yaml)

    find_package(yaml-cpp CONFIG REQUIRED)
    if (yaml-cpp_FOUND)
        message("yaml-cpp_dir=${yaml-cpp_INCLUDE_DIRS}")
        message("yaml-cpp_library=${yaml-cpp_LIBRARYS}")
        link_libraries(yaml-cpp)
    endif ()

endfunction()


function(get_leveldb)

    find_package(leveldb CONFIG REQUIRED)
    if (leveldb_FOUND)
        link_libraries(leveldb::leveldb)
    endif ()

endfunction()


function(get_libgo)

    find_package(libgo CONFIG REQUIRED)
    if (libgo_FOUND)
        link_libraries(libgo::libgo)
    endif ()

endfunction()


function(get_nlohmann_json)

    #The package nlohmann-json provides CMake targets:
    find_package(nlohmann_json CONFIG REQUIRED)
    if (nlohmann_json_FOUND)
        message("nlohmann_json_dir=${nlohmann_json_INCLUDE_DIRS}")
        message("nlohmann_json_library=${nlohmann_json_LIBRARYS}")

        #The package nlohmann-json can be configured to not provide implicit conversions via a custom triplet file:
        set(nlohmann-json_IMPLICIT_CONVERSIONS ON)

        # link
        link_libraries(nlohmann_json::nlohmann_json)
    endif ()

endfunction()


function(get_libmodbus)

    # this is heuristically generated, and may not be correct
    find_package(libmodbus CONFIG REQUIRED)
    if (libmodbus_FOUND)

        # link
        link_libraries(modbus)
    endif ()

endfunction()

function(get_mqtt_cpp)

    # base asio
    find_package(mqtt_cpp_iface CONFIG REQUIRED)
    if (mqtt_cpp_iface_FOUND)

        # link
        link_libraries(mqtt_cpp_iface::mqtt_cpp_iface)
    endif ()

endfunction()


function(get_libgo_cpp)

    # this is heuristically generated, and may not be correct
    find_package(libgo CONFIG REQUIRED)
    if (libgo_FOUND)
        link_libraries(libgo::libgo)
    endif ()

endfunction()

#abseil
function(get_absl)

    # this is heuristically generated, and may not be correct
    find_package(absl CONFIG REQUIRED)
    if (absl_FOUND)
        # note: 134 additional targets are not displayed.
        link_libraries(absl::any absl::base absl::bits absl::city)
    endif ()
endfunction()

#zerormq
function(get_ZeroMQ)
    # this is heuristically generated, and may not be correct
    find_package(ZeroMQ CONFIG REQUIRED)
    if (ZeroMQ_FOUND)
        # note: 134 additional targets are not displayed.
        link_libraries(libzmq)
    endif ()
endfunction()

function(get_range)
    find_package(range-v3 CONFIG REQUIRED)
    if (range-v3_FOUND)
        link_libraries(range-v3::meta range-v3::concepts range-v3::range-v3)
    endif ()
endfunction()

function(get_benchmark)
    find_package(benchmark CONFIG REQUIRED)
    if (benchmark_FOUND)
        link_libraries(benchmark::benchmark benchmark::benchmark_main)
    endif ()
endfunction()

function(get_grpc)
    find_package(gRPC CONFIG REQUIRED)
    if (gRPC_FOUND)
        link_libraries(gRPC::gpr gRPC::grpc gRPC::grpc++ gRPC::grpc++_alts)
    endif ()
endfunction()

function(get_ccache)
    find_program(CCACHE_FOUND ccache)
    if (CCACHE_FOUND)
        set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
        set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
    endif (CCACHE_FOUND)
endfunction()